<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>entry_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_testing_fs_entry_test.js.html">entry_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.testing.fs.EntryTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.testing.fs.EntryTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.fs.DirectoryEntry&#39;);
<a name="line19"></a>goog.require(&#39;goog.fs.Error&#39;);
<a name="line20"></a>goog.require(&#39;goog.testing.AsyncTestCase&#39;);
<a name="line21"></a>goog.require(&#39;goog.testing.MockClock&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.fs.FileSystem&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line24"></a>
<a name="line25"></a>var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
<a name="line26"></a>var fs, file, mockClock;
<a name="line27"></a>
<a name="line28"></a>function setUp() {
<a name="line29"></a>  mockClock = new goog.testing.MockClock(true);
<a name="line30"></a>
<a name="line31"></a>  fs = new goog.testing.fs.FileSystem();
<a name="line32"></a>  file = fs.getRoot().
<a name="line33"></a>      getDirectorySync(&#39;foo&#39;, goog.fs.DirectoryEntry.Behavior.CREATE).
<a name="line34"></a>      getFileSync(&#39;bar&#39;, goog.fs.DirectoryEntry.Behavior.CREATE);
<a name="line35"></a>}
<a name="line36"></a>
<a name="line37"></a>function tearDown() {
<a name="line38"></a>  mockClock.uninstall();
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function testGetName() {
<a name="line42"></a>  assertEquals(&#39;bar&#39;, file.getName());
<a name="line43"></a>}
<a name="line44"></a>
<a name="line45"></a>function testGetFullPath() {
<a name="line46"></a>  assertEquals(&#39;/foo/bar&#39;, file.getFullPath());
<a name="line47"></a>  assertEquals(&#39;/&#39;, fs.getRoot().getFullPath());
<a name="line48"></a>}
<a name="line49"></a>
<a name="line50"></a>function testGetFileSystem() {
<a name="line51"></a>  assertEquals(fs, file.getFileSystem());
<a name="line52"></a>}
<a name="line53"></a>
<a name="line54"></a>function testMoveTo() {
<a name="line55"></a>  file.moveTo(fs.getRoot()).addCallback(function(newFile) {
<a name="line56"></a>    assertTrue(file.deleted);
<a name="line57"></a>    assertFalse(newFile.deleted);
<a name="line58"></a>    assertEquals(&#39;/bar&#39;, newFile.getFullPath());
<a name="line59"></a>    assertEquals(fs.getRoot(), newFile.parent);
<a name="line60"></a>    assertEquals(newFile, fs.getRoot().getFileSync(&#39;bar&#39;));
<a name="line61"></a>    assertFalse(fs.getRoot().getDirectorySync(&#39;foo&#39;).hasChild(&#39;bar&#39;));
<a name="line62"></a>
<a name="line63"></a>    asyncTestCase.continueTesting();
<a name="line64"></a>  });
<a name="line65"></a>  waitForAsync(&#39;waiting for file move&#39;);
<a name="line66"></a>}
<a name="line67"></a>
<a name="line68"></a>function testMoveToNewName() {
<a name="line69"></a>  // Advance the clock to an arbitrary, known time.
<a name="line70"></a>  mockClock.tick(71);
<a name="line71"></a>  file.moveTo(fs.getRoot(), &#39;baz&#39;).
<a name="line72"></a>      addCallback(function(newFile) {
<a name="line73"></a>        mockClock.tick();
<a name="line74"></a>        assertTrue(file.deleted);
<a name="line75"></a>        assertFalse(newFile.deleted);
<a name="line76"></a>        assertEquals(&#39;/baz&#39;, newFile.getFullPath());
<a name="line77"></a>        assertEquals(fs.getRoot(), newFile.parent);
<a name="line78"></a>        assertEquals(newFile, fs.getRoot().getFileSync(&#39;baz&#39;));
<a name="line79"></a>
<a name="line80"></a>        var oldParentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line81"></a>        assertFalse(oldParentDir.hasChild(&#39;bar&#39;));
<a name="line82"></a>        assertFalse(oldParentDir.hasChild(&#39;baz&#39;));
<a name="line83"></a>
<a name="line84"></a>        return oldParentDir.getLastModified();
<a name="line85"></a>      }).
<a name="line86"></a>      addCallback(function(lastModifiedDate) {
<a name="line87"></a>        assertEquals(71, lastModifiedDate.getTime());
<a name="line88"></a>        var oldParentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line89"></a>        return oldParentDir.getMetadata();
<a name="line90"></a>      }).
<a name="line91"></a>      addCallback(function(metadata) {
<a name="line92"></a>        assertEquals(71, metadata.modificationTime.getTime());
<a name="line93"></a>        return fs.getRoot().getLastModified();
<a name="line94"></a>      }).
<a name="line95"></a>      addCallback(function(rootLastModifiedDate) {
<a name="line96"></a>        assertEquals(71, rootLastModifiedDate.getTime());
<a name="line97"></a>        return fs.getRoot().getMetadata();
<a name="line98"></a>      }).
<a name="line99"></a>      addCallback(function(rootMetadata) {
<a name="line100"></a>        assertEquals(71, rootMetadata.modificationTime.getTime());
<a name="line101"></a>        asyncTestCase.continueTesting();
<a name="line102"></a>      });
<a name="line103"></a>  waitForAsync(&#39;waiting for file move&#39;);
<a name="line104"></a>}
<a name="line105"></a>
<a name="line106"></a>function testMoveDeletedFile() {
<a name="line107"></a>  assertFailsWhenDeleted(function() { return file.moveTo(fs.getRoot()); });
<a name="line108"></a>}
<a name="line109"></a>
<a name="line110"></a>function testCopyTo() {
<a name="line111"></a>  mockClock.tick(61);
<a name="line112"></a>  file.copyTo(fs.getRoot()).
<a name="line113"></a>      addCallback(function(newFile) {
<a name="line114"></a>        assertFalse(file.deleted);
<a name="line115"></a>        assertFalse(newFile.deleted);
<a name="line116"></a>        assertEquals(&#39;/bar&#39;, newFile.getFullPath());
<a name="line117"></a>        assertEquals(fs.getRoot(), newFile.parent);
<a name="line118"></a>        assertEquals(newFile, fs.getRoot().getFileSync(&#39;bar&#39;));
<a name="line119"></a>
<a name="line120"></a>        var oldParentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line121"></a>        assertEquals(file, oldParentDir.getFileSync(&#39;bar&#39;));
<a name="line122"></a>        return oldParentDir.getLastModified();
<a name="line123"></a>      }).
<a name="line124"></a>      addCallback(function(lastModifiedDate) {
<a name="line125"></a>        assertEquals(&#39;The original parent directory was not modified.&#39;,
<a name="line126"></a>                     0, lastModifiedDate.getTime());
<a name="line127"></a>        var oldParentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line128"></a>        return oldParentDir.getMetadata();
<a name="line129"></a>      }).
<a name="line130"></a>      addCallback(function(metadata) {
<a name="line131"></a>        assertEquals(&#39;The original parent directory was not modified.&#39;,
<a name="line132"></a>                     0, metadata.modificationTime.getTime());
<a name="line133"></a>        return fs.getRoot().getLastModified();
<a name="line134"></a>      }).
<a name="line135"></a>      addCallback(function(rootLastModifiedDate) {
<a name="line136"></a>        assertEquals(61, rootLastModifiedDate.getTime());
<a name="line137"></a>        return fs.getRoot().getMetadata();
<a name="line138"></a>      }).
<a name="line139"></a>      addCallback(function(rootMetadata) {
<a name="line140"></a>        assertEquals(61, rootMetadata.modificationTime.getTime());
<a name="line141"></a>        asyncTestCase.continueTesting();
<a name="line142"></a>      });
<a name="line143"></a>  waitForAsync(&#39;waiting for file copy&#39;);
<a name="line144"></a>}
<a name="line145"></a>
<a name="line146"></a>function testCopyToNewName() {
<a name="line147"></a>  file.copyTo(fs.getRoot(), &#39;baz&#39;).addCallback(function(newFile) {
<a name="line148"></a>    assertFalse(file.deleted);
<a name="line149"></a>    assertFalse(newFile.deleted);
<a name="line150"></a>    assertEquals(&#39;/baz&#39;, newFile.getFullPath());
<a name="line151"></a>    assertEquals(fs.getRoot(), newFile.parent);
<a name="line152"></a>    assertEquals(newFile, fs.getRoot().getFileSync(&#39;baz&#39;));
<a name="line153"></a>    assertEquals(file, fs.getRoot().getDirectorySync(&#39;foo&#39;).getFileSync(&#39;bar&#39;));
<a name="line154"></a>    assertFalse(fs.getRoot().getDirectorySync(&#39;foo&#39;).hasChild(&#39;baz&#39;));
<a name="line155"></a>
<a name="line156"></a>    asyncTestCase.continueTesting();
<a name="line157"></a>  });
<a name="line158"></a>  waitForAsync(&#39;waiting for file copy&#39;);
<a name="line159"></a>}
<a name="line160"></a>
<a name="line161"></a>function testCopyDeletedFile() {
<a name="line162"></a>  assertFailsWhenDeleted(function() { return file.copyTo(fs.getRoot()); });
<a name="line163"></a>}
<a name="line164"></a>
<a name="line165"></a>function testRemove() {
<a name="line166"></a>  mockClock.tick(57);
<a name="line167"></a>  file.remove().
<a name="line168"></a>      addCallback(function() {
<a name="line169"></a>        mockClock.tick();
<a name="line170"></a>        var parentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line171"></a>
<a name="line172"></a>        assertTrue(file.deleted);
<a name="line173"></a>        assertFalse(parentDir.hasChild(&#39;bar&#39;));
<a name="line174"></a>
<a name="line175"></a>        return parentDir.getLastModified();
<a name="line176"></a>      }).
<a name="line177"></a>      addCallback(function(date) {
<a name="line178"></a>        assertEquals(57, date.getTime());
<a name="line179"></a>        var parentDir = fs.getRoot().getDirectorySync(&#39;foo&#39;);
<a name="line180"></a>        return parentDir.getMetadata();
<a name="line181"></a>      }).
<a name="line182"></a>      addCallback(function(metadata) {
<a name="line183"></a>        assertEquals(57, metadata.modificationTime.getTime());
<a name="line184"></a>        asyncTestCase.continueTesting();
<a name="line185"></a>      });
<a name="line186"></a>  waitForAsync(&#39;waiting for file removal&#39;);
<a name="line187"></a>}
<a name="line188"></a>
<a name="line189"></a>function testRemoveDeletedFile() {
<a name="line190"></a>  assertFailsWhenDeleted(function() { return file.remove(); });
<a name="line191"></a>}
<a name="line192"></a>
<a name="line193"></a>function testGetParent() {
<a name="line194"></a>  file.getParent().addCallback(function(p) {
<a name="line195"></a>    assertEquals(file.parent, p);
<a name="line196"></a>    assertEquals(fs.getRoot().getDirectorySync(&#39;foo&#39;), p);
<a name="line197"></a>    assertEquals(&#39;/foo&#39;, p.getFullPath());
<a name="line198"></a>
<a name="line199"></a>    asyncTestCase.continueTesting();
<a name="line200"></a>  });
<a name="line201"></a>  waitForAsync(&#39;waiting for file parent&#39;);
<a name="line202"></a>}
<a name="line203"></a>
<a name="line204"></a>function testGetDeletedFileParent() {
<a name="line205"></a>  assertFailsWhenDeleted(function() { return file.getParent(); });
<a name="line206"></a>}
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>function assertFailsWhenDeleted(fn) {
<a name="line210"></a>  file.remove().addCallback(fn).
<a name="line211"></a>      addCallback(function() { fail(&#39;Expected an error&#39;); }).
<a name="line212"></a>      addErrback(function(err) {
<a name="line213"></a>        assertEquals(goog.fs.Error.ErrorCode.NOT_FOUND, err.code);
<a name="line214"></a>        asyncTestCase.continueTesting();
<a name="line215"></a>      });
<a name="line216"></a>  waitForAsync(&#39;waiting for file operation&#39;);
<a name="line217"></a>}
<a name="line218"></a>
<a name="line219"></a>function waitForAsync(msg) {
<a name="line220"></a>  asyncTestCase.waitForAsync(msg);
<a name="line221"></a>  mockClock.tick();
<a name="line222"></a>}
</pre>


</body>
</html>
